package com.tarena.lbs.service.impl;

import com.tarena.lbs.mapper.UserGroupMapper;
import com.tarena.lbs.dto.UserGroupParam;
import com.tarena.lbs.dto.UserGroupQuery;
import com.tarena.lbs.entity.UserGroup;
import com.tarena.lbs.service.UserGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class UserGroupServiceImpl implements UserGroupService {
    @Autowired
    private UserGroupMapper userGroupMapper;
    @Override
    public void save(UserGroupParam userGroupParam) {
        log.debug("用户群新增请求:{}",userGroupParam);
        UserGroup userGroup=new UserGroup();
        BeanUtils.copyProperties(userGroupParam,userGroup);
        if (userGroup.getId()==null){
            userGroup.setCreateAt(new Date());
            userGroupMapper.save(userGroup);
        }else {
            userGroupMapper.update(userGroup);
        }
    }

    @Override
    public List<UserGroup> select(UserGroupQuery userGroupQuery) {
        log.debug("用户群查询请求:{}",userGroupQuery);
        List<UserGroup> list=userGroupMapper.select(userGroupQuery);
        return list;
    }

    @Override
    public void delete(Long id) {
        log.debug("用户群删除请求:{}",id);
        userGroupMapper.delete(id);
    }
}
